<template>
	<view class="content">
		<!--产品，客户列表 -->
		<customersTow ref="customersTow" 
			@setGoodsThree="setGoodsThree" 
			@setCustomInfo="setCustomInfo"
			@addCustomer="addCustomer"
			@upDownClick="upDownClick"></customersTow>
		<!-- 客户详情页面 -->
		<customersThree 
			ref="customersThree"  
			v-show="curIndex == 1"
			:xsgf="15" 
			@removeCustom="removeCustom" 
			@bill="bill" 
			@editCustomer="editCustomer"
			@updataCustomList="updataCustomList"> 
		</customersThree>
		<!-- 添加/编辑客户 -->
		<customersAdd 
			ref="customersAdd"  
			v-show="curIndex == 2" 
			:actType="actType"
			@addCustomSuccess="addCustomSuccess">
		</customersAdd>
		<!-- 导入客户窗口 -->
		<importCustomers ref="importCustomers"></importCustomers>
		<!-- 上传下载菜单 -->
		<upAndDownLoadMenu ref="upAndDownLoadMenu" :md="mdKh" @showUploadCustomWin="showUploadCustomWin"></upAndDownLoadMenu>
	</view>
</template>

<script>
	import customersTow from '../../components/customers/CustomersTow.vue';
	
	import customersThree from '../../components/customers/CustomersThree.vue';
		
	
	import lang from "../../js/conf/Lang.js";
	import staticConst from '../../js/const/StaticConst.js';
	
	import goodsAdd from "../../components/goods/GoodsAdd.vue";
	
	import eventCtrl from "../../js/event/EventCtrl.js";
	import goodsCtrl from "../../js/gd/GoodsCtrl.js";
	
	import vipCtrl from "../../js/vip/VipCtrl.js";
	
	import customCtrl from "../../js/custom/CustomCtrl.js";
	
	import upAndDownLoadMenu from "../../components/comm/UpAndDownLoadMenu.vue";
	
	import importCustomers from "../../components/customers/ImportCustomers.vue";
	
	import customersAdd from "../../components/customers/CustomersAdd.vue";
	
	export default {
		components: { 
			customersTow, customersThree ,upAndDownLoadMenu,importCustomers,customersAdd},
		data() {
			return {
				curPage:staticConst.MD_KH,
				actType:0 ,// 0:新增客户 1：编辑编辑
				isNotData :false, // 没有数据
				mdKh:staticConst.MD_KH,//模块
				curIndex:1,  //1,
			}
		},
		
		onLoad() {
			
		},
		
		onShow() {
		},
		
		onHide() {
		},
		
		onUnload() {
		},
		
		onReady() {
			if(customCtrl.addCustomer == 1)
			{
				customCtrl.addCustomer = 0;//用完，重置
				this.addCustomer();
			}
			else
			{
				this.$refs.customersTow.initData();
			}
		},
				
		methods: {
			
			/****显示上传产品列表窗口****/
			showUploadCustomWin()
			{
				this.$refs.importCustomers.show("show");
			},
			
			/*****显示上传下载菜单****/
			upDownClick()
			{
				this.isClickUpDownBtn = true;
				this.$refs.upAndDownLoadMenu.show();
			},
			
			/***点击产品列表处理**/
			setGoodsThree(data)
			{
				// this.$refs.receiptInfo.addGoodsReceipt(data);
			},
			
			/****设置开单用户*******/
			setCustomInfo(data)
			{
				// this.$refs.receiptInfo.getCustomInfo(data,isCheckOut);
				/****选中客户******/
				this.curIndex = 1;
				this.$refs.customersThree && this.$refs.customersThree.loadCustomInfo(data,false);
			},
			
			/****删除客户*****/
			removeCustom(id)
			{
			    this.$refs.customersTow.removeCustom(id);
			},
			
			/****开单操作****/
			bill(data)
			{
				let CopyData = JSON.parse(JSON.stringify(data))
				customCtrl.setBillCustom(CopyData);
				uni.$emit('write_bill',1);
			},
			
			/****添加客户****/
			addCustomer()
			{
				this.curIndex = 2;
				this.actType = 0;
				this.$refs.customersAdd.init();
			},
			
			/****编辑客户****/
			editCustomer(data)
			{
				this.curIndex = 2;
				this.actType = 1;
				this.$refs.customersAdd.init(data);
			},
			
			/*******添加修改客户成功*******/
			addCustomSuccess(data)
			{
				this.curIndex = 1;
				if(data.act == 0)//新增客户详情
				{
					this.$refs.customersTow.addNewCustomer();
				}
				else//编辑客户详情
				{
					this.$refs.customersThree.editCustomInfo(data.id);
				}
			},
			
			/***编辑客户更新客户****/
			updataCustomList(data)
			{
				this.$refs.customersTow.updataCustomList(data);
			},
		},
	}
</script>
<style lang="scss">
	.content
	{
		display: flex;
		justify-content: flex-start;
		min-width: 820px;
		height: 100%;
		position: relative;
	}
	
</style>